package org.example.factory.config;

import lombok.Getter;
import org.example.property.PropertyValues;

/**
 * @Author: luyg
 * @Date: 2024/09/05/23:28
 * @Description: bean的class定义及属性
 */
@Getter
@SuppressWarnings({"rawtypes"})
public class BeanDefinition {
    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;

    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;

    private Class beanClass;
    /**
     * bean属性里的字段内容
     */

    private PropertyValues propertyValues;
    /**
     * 初始化方法
     */
    private String initMethodName;
    /**
     * 销毁方法
     */
    private String destroyMethodName;

    private String scope=SCOPE_SINGLETON;

    private boolean singleton = true;
    private boolean prototype = false;

    public BeanDefinition(Class beanClass) {
        this.beanClass = beanClass;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }

    public void setScope(String scope) {
        this.scope = scope;
        this.singleton = SCOPE_SINGLETON.equals(scope);
        this.prototype = SCOPE_PROTOTYPE.equals(scope);
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }
    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }
}
